import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../controllers/subscription_controller.dart';

class SubscriptionTierTabs extends StatelessWidget {
  const SubscriptionTierTabs({super.key});

  @override
  Widget build(BuildContext context) {
    final SubscriptionController controller = Get.find();

    // 图标资源映射
    final List<Map<String, String>> tierIcons = [
      {
        'normal': 'assets/images/icon_basic_nor.png',
        'selected': 'assets/images/icon_basic_sel.png',
      },
      {
        'normal': 'assets/images/icon_moderate_nor.png',
        'selected': 'assets/images/icon_moderate_sel.png',
      },
      {
        'normal': 'assets/images/icon_advanced_nor.png',
        'selected': 'assets/images/icon_advanced_sel.png',
      },
      {
        'normal': 'assets/images/icon_toptier_nor.png',
        'selected': 'assets/images/icon_toptier_sel.png',
      },
    ];

    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
      child: Row(
        children:
            tierIcons.asMap().entries.map((entry) {
              final index = entry.key;
              final icons = entry.value;

              return Expanded(
                child: Container(
                  margin: EdgeInsets.symmetric(horizontal: 2.w),
                  child: Obx(() {
                    final isSelected = index == controller.selectedTier.value;
                    return GestureDetector(
                      onTap: () {
                        controller.selectTier(index);
                      },
                      child: Container(
                        padding: EdgeInsets.symmetric(vertical: 8.h),
                        child: Image.asset(
                          isSelected ? icons['selected']! : icons['normal']!,
                          width: 80.w,
                          height: 40.h,
                          fit: BoxFit.contain,
                        ),
                      ),
                    );
                  }),
                ),
              );
            }).toList(),
      ),
    );
  }
}
